﻿<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link type="text/css" href="../Skin/Plane/css/List.css" rel="stylesheet" />
    <link type="text/css" href="../Layui/css/layui.css" rel="stylesheet" media="all">
    <link rel="stylesheet" href="../Css/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="../Layui/layui.js"></script>
    <script type="text/javascript" src="../Htc/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="../Htc/jquery.ztree.core.min.js"></script>
    <script type="text/javascript" src="../Htc/jquery.ztree.excheck.min.js"></script>
    <script type="text/javascript" src="../Htc/CustomForm.js?10"></script>
    <script type="text/javascript">
var treeType;
var showIcon=false;
var showCheck=true;

//加载
$(document).ready(function () {
    layui.use('layer', function () {       
    });
    //初始化
    var setting = {
	    view: {
		    dblClickExpand: false,      //双击展开
		    showLine: true,
		    selectedMulti: false,       //选择多个,按ctrl
		    showIcon:showIcon           //图标
	    },
	    check: {
			enable: showCheck   //复选
	    },
	    data: {
		    simpleData: {
			    enable:true
		    }
	    },
	    callback: {
		    beforeClick: function(treeId, treeNode) {
			    var zTree = $.fn.zTree.getZTreeObj("tree");
			    if (treeNode.isParent) {
			        //展开
				    zTree.expandNode(treeNode);
				    return false;
			    }else {
			        //选择

			    }
		    }
	    }
    };

    $.ajax({
        url: "../Sys/Grant/Data",
        dataType:"json",
        data: {
            type:"@ViewBag.type",
            id:"@ViewBag.id",
            keyCode:"@ViewBag.keyCode",
            t:new Date().getTime()
        },
        success: function( data ) {
            $.fn.zTree.init($("#tree"), setting, data.data);
        }
    });

 });
function GrantSave()
{
	var zTree = $.fn.zTree.getZTreeObj("tree");
	var nodes = zTree.getCheckedNodes(true);
	var menuId="''";
	for(var i=0;i<nodes.length;i++)
	{
		var obj=nodes[i];
		if(obj.check_Child_State!=1)
			menuId+=",'"+obj.id+"'";
	}

    $.ajax({
    	type: "POST",
        url: "../Sys/Grant/SaveData",
        dataType:"json",
        data: {
            type:"@ViewBag.type",
            id:"@ViewBag.id",
            keyCode:"@ViewBag.keyCode",
            menuId:menuId,
            t:new Date().getTime()
        },
        success: function( data ) {
       		callback(data);
        }
    });
}

function MessageAlert(msg) {
    alert(msg)
}
    </script>
</head>
<body class="BodyManager">

    <div class="grantTree" style="height:358px;"><div id="tree" class="ztree"></div></div>
    <div class="poppanButton">
        <button class="layui-btn layui-btn-normal" id="btn_ent" onclick="GrantSave();return false;">确定</button>
        <button class="layui-btn layui-btn-primary" onclick="try{parent.HideModal('popEdit');}catch(e){parent.win.removewin(parent.win.currentwin);};return false;">关闭</button>
    </div>
</body>
</html>
